package com.learn.thread;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class TestUnSafeThreadSynchronized6 {
    public static void main(String[] args) throws InterruptedException {
        List<String> stringList = Collections.synchronizedList(new ArrayList<>());
        int threadCount = 10_000;
        ExecutorService executorService = Executors.newFixedThreadPool(200);
        for (int i = 0; i < threadCount; i++) {
            executorService.submit(() -> {
                stringList.add(Thread.currentThread().getName());
            });
        }
        executorService.shutdown();
        executorService.awaitTermination(1, TimeUnit.MINUTES);
        System.out.println(stringList.size());
    }
}
